package com.datastructure.test.rotatestring;

public class RotateString {

    public static void main(String[] args) {
        RotateString rotateString = new RotateString();
        String str1 = "abcd";
        String str2 = "abcd";
        boolean solve = rotateString.solve1(str1, str2);
        System.out.println(solve);
    }

    public boolean solve (String A, String B) {
        // write code here
        if(A.equals(B)){
            return true;
        }
        String str1;
        String str2;
        StringBuilder stringBuilder = null;
        int length = A.length();
        for (int i = 0; i < length; i++) {
            str1=A.substring(0,i);
            str2=A.substring(i,length);
            stringBuilder = new StringBuilder();
            stringBuilder.append(str2);
            stringBuilder.append(str1);
            if(stringBuilder.toString().equals(B)){
                return true;
            }
        }
        return false;
    }

    public boolean solve1 (String A, String B) {
        // write code here
        String str1;
        String str2;
        StringBuilder stringBuilder = null;
        int length = A.length();
        for (int i = 1; i < length-1; i++) {
            str1=A.substring(0,i);
            str2=A.substring(i,length);
            stringBuilder = new StringBuilder();
            stringBuilder.append(str2);
            stringBuilder.append(str1);
            if(stringBuilder.toString().equals(B)){
                return true;
            }
        }
        return false;
    }

    public String solve2 (String str, int n) {
        // write code here
        if(str==null||str.length()==0){
            return str;
        }
        String str1;
        String str2;
        StringBuilder stringBuilder = null;
        int length = str.length();
        if(n>length){
            n=n%length;
        }
        for (int i = 0; i < n; i++) {
            str1=str.substring(0,1);
            str2=str.substring(1,length);
            stringBuilder = new StringBuilder();
            stringBuilder.append(str2);
            stringBuilder.append(str1);
            str=stringBuilder.toString();
        }
        return str;
    }
}
